home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / SourceCode / Tutorial / Cookbook / 17.plot / plotview.psw < prev   
Text File  |  1995-06-12  |  4KB  |  195 lines

  1. defineps createPSDefs()
  2.     /strx 20 string def
  3.     /stry 20 string def
  4.     /str 20 string def
  5.     /divx ( per division on x, ) def
  6.     /divy ( per division on y) def
  7.     
  8.     /plotfont {
  9.     % width and height of viewing area on stack
  10.     % make font that is 3 percent of current size
  11.         scale
  12.         /Times-Roman findfont
  13.         0.03 scalefont setfont
  14.     } def
  15.         
  16. endps
  17.  
  18. defineps PSDrawAxis(float ac, x, y, w, h)
  19.     0.0 setlinewidth
  20.     ac setgray
  21.     % draw from edge of x to origin to tip of y
  22.     w x add y moveto
  23.     x y lineto
  24.     x y h add lineto
  25.     stroke
  26.     % now show the location of the origin
  27.     x y h 0.04 mul sub moveto
  28.     gsave        % setup font coordinates
  29.         w h plotfont
  30.         x str cvs show
  31.     grestore     % go back to program coordinates
  32.     x w add y h 0.04 mul sub moveto
  33.     gsave
  34.         w h plotfont
  35.         x w add str cvs     % the end point
  36.         dup stringwidth neg exch neg exch rmoveto show    
  37.     grestore
  38.     %
  39.     % move 1 percent to the left of the axis
  40.     x w 0.01 mul sub y moveto
  41.     gsave            % set up font coordinates
  42.         90.0 rotate
  43.         h w plotfont
  44.         y str cvs show
  45.     grestore        % restore program coordinates
  46.     x w 0.01 mul sub y h add moveto
  47.     gsave
  48.         90 rotate
  49.         h w plotfont
  50.         y h add str cvs     % top end of y axis 
  51.         dup stringwidth neg exch neg exch rmoveto show
  52.     grestore
  53. endps
  54.  
  55. defineps PSWriteXLabel(float gray,x,y,w,h; char *lab)
  56. % pass in the min and size of both axis along with the string
  57.     gsave
  58.     gray setgray
  59.     x w 2.0 div add        %center position of axis
  60.     y h 0.04 mul sub    % figure out ylocation
  61.     moveto
  62.     w h plotfont
  63.     (lab) stringwidth 2.0 div    %halfo of the length of the string
  64.     neg 0 rmoveto        %move back half 
  65.     (lab)show
  66.     grestore
  67. endps
  68.  
  69. defineps PSWriteYLabel(float gray,x,y,w,h; char *lab)
  70. % pass in the min and size of both axis along with the string
  71.     gsave
  72.     gray setgray
  73.     x w 0.01 mul sub    % location on xaxis
  74.     y h 2.0 div add        % center of y axis
  75.     moveto
  76.     90.0 rotate
  77.     h w plotfont
  78.     (lab) stringwidth 2.0 div    % half of length of string
  79.     neg 0 exch rmoveto        % move down half
  80.     (lab)show
  81.     grestore
  82. endps
  83.  
  84. defineps PSEnableInstance(float instcol)
  85.     gsave        % save the original coordinate position
  86.     true setinstance
  87.     instcol setgray    % allow user to set instance color 
  88.     0.0 setlinewidth    % set smallest possible line
  89. endps
  90.  
  91. defineps PSDisableInstance()
  92.     %newinstance    % remove last instance drawing
  93.     false setinstance    %resume normal drawing
  94.     grestore    % return to original gstate
  95. endps
  96.  
  97. defineps PSDrawCrossHair(float startx, starty, minx, maxx, miny, maxy)
  98. % minx, miny, maxx, maxy are the bounds of the page
  99. % startx, starty is the point where the cursor is
  100.     /doright    
  101.         {
  102.             startx strx cvs show
  103.             (,) show
  104.             starty stry cvs show
  105.         } def
  106.     /doleft
  107.         {
  108.             starty stry cvs
  109.             dup stringwidth neg exch neg exch
  110.             rmoveto 
  111.             (,) 
  112.             dup stringwidth neg exch neg exch
  113.             rmoveto 
  114.             startx strx cvs
  115.             dup stringwidth neg exch neg exch
  116.             rmoveto
  117.             show show show
  118.         }def
  119.     %newinstance
  120.     startx miny moveto
  121.     startx maxy lineto
  122.     minx starty moveto
  123.     maxx starty lineto
  124.     stroke
  125.     startx starty dup .01 mul add moveto     % go up 1% off access 
  126.     gsave % we use seperate context so that font scaling is easier
  127.     %/Times-Roman findfont
  128.     /Courier findfont
  129.     maxx minx sub  % make the view unit length
  130.     maxy miny sub  % and unit height
  131.     scale
  132.     0.05 scalefont
  133.     setfont
  134.     maxx minx sub 2.0 div    %calc center 
  135.     startx lt         % is start x to right of center
  136.     {doleft} {doright} ifelse    % put text on wide side of cursor
  137.     grestore
  138.     %showpage
  139. endps
  140.  
  141. defineps PSOverlayBox(float minx, maxx, miny, maxy)
  142.     %newinstance
  143.     gsave
  144.     0 setlinewidth
  145.     minx miny moveto
  146.     minx maxy lineto
  147.     maxx miny moveto
  148.     maxx maxy lineto
  149.     stroke
  150.     grestore
  151. endps
  152.  
  153.  
  154. defineps PSGridWrite(float textcol, gx, gy, minx, maxx, miny, maxy)
  155. % write out the x and y grid values across the top
  156. % for some reason, when going to the printer the literal strings must be in
  157. % definintions ... not as literals in the code
  158.     gsave
  159.         textcol setgray
  160.         maxx minx sub 0.15 mul minx add   % make it 15 percent  across
  161.         maxy miny sub 1.01 mul miny add   % make just above top
  162.         moveto
  163.         maxx minx sub % make the view a unit length
  164.         maxy miny sub % make it a unit height
  165.         plotfont
  166.         gx str cvs show
  167.         divx show
  168.         gy str cvs show
  169.         divy show
  170.     grestore
  171. endps
  172.  
  173.  
  174. defineps PSBox(float lc, lw, x, y, w, h)
  175. % draw a box that starts at x,y and is w wide and h high
  176.     lc setgray
  177.     lw setlinewidth
  178.     x y moveto
  179.     x y h add lineto
  180.     x w add y h add lineto
  181.     x w add y lineto
  182.     x y lineto
  183.     stroke
  184. endps
  185.  
  186. defineps PSfillrect(float x, y, xn, yn)
  187. % fill a box with opposite corners x,y and xn,yn
  188.     x y moveto
  189.     x yn lineto
  190.     xn yn lineto
  191.     xn y lineto
  192.     x y lineto
  193.     fill
  194. endps
  195.